﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IceCS.DataStructure.Core.String;

namespace IceCS.DataStructure.One2HunderdQ
{
    public class QuestionReader
    {
        ArrayList questionList;
        public QuestionReader()
        {
            questionList = new ArrayList();
            FileStream fs = new FileStream("question.txt", FileMode.Open, FileAccess.Read);
            StreamReader sr = new StreamReader(fs, Encoding.UTF8);
            SequenceString str = ConverFrom(sr.ReadLine());
            while (str.Length != 0)
            {
                int startPos = 0;
                int endPos = 0;
                SequenceString[] temp = new SequenceString[4];
                int i = 0;
                do
                {
                    endPos = str.IndexOf(new SequenceString("|".ToCharArray()), startPos);
                    if (endPos == -1)
                    {
                        endPos = str.Length;

                    }
                    if (endPos != startPos)
                    {
                        temp[i++] = str.SubString(startPos, endPos - startPos);
                    }
                    startPos = endPos + 1;
                } while (startPos<str.Length);
                questionList.Add(temp);
                str = ConverFrom(sr.ReadLine());
            }
        }
        public SequenceString ConverFrom(string text)
        {
            char[] temp = text.ToCharArray();
            return new SequenceString(temp);
        }

        public ArrayList GetQuestionList()
        {
            return questionList;
        }
    }
}
